﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

namespace B13_Ex02_David_300512340_Alexey_321203689
{
    public class AlbumFormLogicProxy : IAlbumLogic
    {
        public AlbumWrapper SelectedAlbum { get; private set; }

        public AlbumFormLogic AlbumLogic { get; set; }

        public AlbumFormLogicProxy(AlbumWrapper i_SelectedAlbum)
        {
            AlbumLogic = new AlbumFormLogic();
            SelectedAlbum = i_SelectedAlbum;
        }

        public void SaveAlbum(AlbumWrapper i_SelectedAlbum, string i_Path, string i_PictureName)
        {
            AlbumLogic.SaveAlbum(i_SelectedAlbum, i_Path, i_PictureName);
        }

        public void SaveSelectedPhotos(string i_Path, string i_PictureName, ListBox i_ListBoxPictures)
        {
            AlbumLogic.SaveSelectedPhotos(i_Path, i_PictureName, i_ListBoxPictures);
        }

        /// <summary>
        ///  Loading the photos from the listBox for the slide show.
        /// </summary>
        public List<Image> PhotosPreLoader(List<PhotoWrapper> i_PhotosList)
        {
            List<Image> imagesList = new List<Image>();
            Thread thread = new Thread(() => { imagesList = AlbumLogic.PhotosPreLoader(i_PhotosList); });

            thread.Start();
            notifyUserWhenStartLoadingImages();
            thread.Join();
            notifyUserWhenDoneLoadingImages();

            return imagesList;
        }

        private void notifyUserWhenStartLoadingImages()
        {
            MessageBox.Show("Starting to load images, please wait.", "Loading...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
        }

        private void notifyUserWhenDoneLoadingImages()
        {
            MessageBox.Show("Finished loading images.", "Finished", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
        }
    }
}